home *** CD-ROM | disk | FTP | other *** search
- Path: hydra.acs.uci.edu!awu
- From: awu@hydra.acs.uci.edu (Alex Wu)
- Newsgroups: comp.lang.c
- Subject: Simulating a Memory Manager
- Date: 12 Apr 1996 11:05:51 GMT
- Organization: University of California, Irvine
- Message-ID: <4kldef$png@news.service.uci.edu>
- NNTP-Posting-Host: hydra.acs.uci.edu
-
- Hi, maybe you guys can help me, Im having problems moving around in memory.
-
- Okay Im suppose to write a mock-memory manager, that keeps tracks of
- a list of pointers that points to memory blocks are in use, and a list
- of open 'holes' in the memory. At the beginning of each block, there
- is a field for tag (nominate if it's full or open) and size (# of bytes
- in use).
-
-
- char *blocks[100]; /* keeps tracks of pointers that points to the
- used blocks */
-
- struct template
- {
- short tag;
- short size;
- };
-
- char MM[32768]; /* size of the memory block we are keeping */
- char *MEM_PTR = MM; /* points to the beginning of the block */
-
-
- Okay, we first initialize the memory, so it's just one big hole.
-
- struct template *HEAD
-
- init_mem()
- {
- HEAD->tag = TRUE; /* it's a hole */
- HEAD->size = 32768;
- }
-
-
- Now it has to handle requests. n is the number of bytes that I have to
- set aside. Once I set it aside, I have to return the begining of the block.
- And of course adjust any open holes.
-
- char *MM_Request(int n)
- {
- struct template *s;
-
- s = HEAD;
- if (s->size >= n) { /* have the space, allocate it */
-
- HEAD = s+n; /* moves down n byte to mark the new location of
- the open block for next request ?????? */
- HEAD->size = s->size - n; /* remaining open mem size */
- HEAD->tag = TRUE; /* its a hole */
- return (char *) s; /* returns the head of the request byte */
- }
- }
-
- main ()
- {
- loop {
- blocks[counter] = MM_request(random bytes);
- }
- }
-
-
- Now the program goes okay until it goes over 10k bytes. any suggestions?
-
-
- Alex
-
-
-
-
-